package com.haibei.view;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

import com.haibei.R;

public class SingleTabInidcatorView {

	private Activity activity;
	private ImageView tabImaeView;
	private TextView tabTextView;

	private int drableNormal;
	private int drableCheck;
	private String indicatorText;

	private View rootView;

	private SubTabView tabContent;
	private boolean checked;

	private final int TEXT_COLOR_CHECK = 0xff4ABDCC;
	private final int TEXT_COLOR_UNCHECK = 0xffADB7B9;

	public SingleTabInidcatorView(Activity activity, int drableNormal, int drableCheck, String indicatorText, SubTabView subTab) {
		this.activity = activity;
		this.drableNormal = drableNormal;
		this.drableCheck = drableCheck;
		this.indicatorText = indicatorText;
		this.tabContent = subTab;
		initView();
	}

	public void initView() {
		this.rootView = View.inflate(activity, R.layout.tab_button_indicator, null);
		this.tabImaeView = (ImageView) this.rootView.findViewById(R.id.tabIndicatorImage);
		this.tabImaeView.setImageResource(drableNormal);
		this.tabTextView = (TextView) this.rootView.findViewById(R.id.tabIndicatorText);
		this.tabTextView.setText(indicatorText);
	}

	public void setBackGroundColor(int color) {
		this.rootView.setBackgroundColor(color);
	}

	public void setBackGroundDrawable(Drawable drable) {
		this.rootView.setBackgroundDrawable(drable);
	}

	public void check() {
		this.tabImaeView.setImageResource(drableCheck);
		this.rootView.setBackgroundResource(R.drawable.bg_tab_check);
		this.tabTextView.setTextColor(TEXT_COLOR_CHECK);
		this.checked = true;
		this.rootView.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.layout_scale));
	}

	public void uncheck() {
		this.rootView.setBackgroundDrawable(null);
		this.tabImaeView.setImageResource(drableNormal);
		this.tabTextView.setTextColor(TEXT_COLOR_UNCHECK);
		this.checked = false;
	}

	public SubTabView getSubTab() {
		return tabContent;
	}

	public View getTabContentView() {
		return tabContent.getView();
	}

	public boolean isChecked() {
		return checked;
	}

	public void setChecked(boolean checked) {
		this.checked = checked;
	}

	public View getView() {
		return this.rootView;
	}
}
